<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'我的客户'),
);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$this->worker_id);
	if(!empty($_RQ['title'])){
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		$params2['name like']='%'.trim($_RQ['title']).'%';
		$mids=pdo_getall('jy_yiliao_user',$params2,array('id','name'),'mid');
		if($mids){
			$mids=array_keys($mids);
			$params['mid']=$mids;
		}else{
			$bodyids=pdo_getall('jy_yiliao_body',$params2,array('id','name'),'id');
			if($bodyids){
				$bodyids=array_keys($bodyids);
			}else{
				$bodyids=-1;
			}
			$params['bodyid']=$bodyids;
		}
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_yiliao_worker_user',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$user=pdo_get('jy_yiliao_user',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$item['mid']),array('name','birth','sex','mobile'));
			$item['username']=$user['name'];
			$item['name']=$user['name'];
			$item['mobile']=$user['mobile'];
			$item['sex']=$user['sex'];
			$item['birth']=json_decode($user['birth'],true);
			$item['year']=$item['birth']['year'];
			if($item['bodyid']){
				$body=pdo_get('jy_yiliao_body',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['bodyid']),array('name','sex','agetime'));
				$item['name']=$body['name'];
				$item['sex']=$body['sex'];
				$item['year']=date('Y',$body['agetime']);
			}
			$item['sex']=$item['sex']==0?'女':'男';
			$item['age']=$item['year']>0?date('Y')-$item['year']:'无';
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'客户信息','type'=>'member'),
			array('title'=>'患者','type'=>'img_string','img'=>'avatar',
			'data'=>array(
				array('title'=>'家长：','name'=>'username'),
				array('title'=>'患者：','name'=>'name','unit'=>'sex')
				)
			),
			array('name'=>'mobile','title'=>'联系电话','type'=>'string'),
			array('name'=>'age','title'=>'年龄','type'=>'string'),
			array('name'=>'from_type','title'=>'渠道来源','type'=>'radio','options'=>'from_type'),
			array('name'=>'workerid','title'=>'大夫','type'=>'select','options'=>'workers','option_title'=>'name'),
		),'action'=>array(
			array('type'=>'modal','action'=>'/onelesson_log/','title'=>'查看病历'),
			array('type'=>'post','op'=>'setfanmsg','title'=>'患者复诊提醒'),
			array('type'=>'post','op'=>'setyaomsg','title'=>'用药提醒'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	$return['from_type']=$this->from_type;
	$return['workers']=pdo_getall('jy_yiliao_worker',array('uniacid'=>$_SESSION['uniacid']),array('id','name'),'id');
	$return['ispay']=array('未支付','已支付');
	exi($return);
}

if($_RQ['op']=='setfanmsg'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择客户！','error');
	}
	$this->model('worker')->upmy_userlog($id,0);
	exi('复诊提醒成功！');
}
if($_RQ['op']=='setyaomsg'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择客户！','error');
	}
	$this->model('worker')->upmy_userlog($id,1);
	exi('用药提醒成功！');
}